# -*- coding: utf-8 -*-
# @Time    : 2022/7/18 13:36
# @Author  : haichuan
# @Email   : 2263126410@163.com
# @File    : xtbs_tj_bumpage.py
# @Software: PyCharm
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import  sleep
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select
from pages.denglu_page import Deng_BasePage

class AddBumPage(Deng_BasePage):
    '''组织架构添加部门'''
    url = ("http://localhost/crm/")
    # 定位器
    add_bumengname = (By.XPATH ,'//*[@id="name"]')
    add_shangjibumeng = (By.XPATH ,'/html/body/div[8]/div[2]/form/div[2]/div/select')
    add_bumengtext = (By.XPATH ,'/html/body/div[8]/div[2]/form/div[3]/div/textarea')
    add_queren = (By.XPATH ,'/html/body/div[8]/div[3]/div/button[1]/span')
    user_Heads = (By.CSS_SELECTOR ,'li.dropdown:nth-child(6) > a:nth-child(1)')
    zzjg_xlk = (By.CSS_SELECTOR ,'li.dropdown:nth-child(6) > ul:nth-child(2) > li:nth-child(4) > a:nth-child(1)')
    zzjg__jgzz = (By.CSS_SELECTOR ,'.page-header > h4:nth-child(1) > small:nth-child(1) > a:nth-child(1)')
    add_bumen = (By.ID ,'add_department')
    def access_bum(self):
        '''进入组织架构页面中添加部门'''
        self.driver.find_element( *self.user_Heads ).click()
        sleep(1)
        self.driver.find_element( *self.zzjg_xlk ).click()
        sleep(1)
        self.driver.find_element( *self.zzjg__jgzz ).click()
        sleep(1)
        self.driver.find_element( *self.add_bumen ).click()

    def bum_name(self,bumname):
        '''在添加部门弹框中'''
        sleep( 2 )
        self.driver.find_element(*self.add_bumengname ).send_keys(bumname)
    def bum_buz(self):
        '''上级部门'''
        xuanze_shangjibumeng =self.driver.find_element( *self.add_shangjibumeng )
        shangjibumeng_add = Select( xuanze_shangjibumeng )
        shangjibumeng_add.select_by_index( 1 )

    def  bum_explain(self,explain):
        self.driver.find_element( *self.add_bumengtext ).send_keys(explain )

    def add_btn(self):
        self.driver.find_element(*self.add_queren).click()